package operation;

import book.BookList;

import java.util.Scanner;

public class ReturnOperation implements IOperation{
    @Override
    public void work(BookList bookList) {
        System.out.println("归还图书");
        System.out.println("输入要归还的书名:");
        Scanner scanner = new Scanner(System.in);
        String name = scanner.nextLine();
        for (int i = 0; i < bookList.getNumber(); i++) {
            if (name.equals(bookList.getBook(i).getName())) {
                if (bookList.getBook(i).getLend()) {
                    bookList.getBook(i).setLend(false);
                    System.out.println("归还成功");
                    return;
                }else {
                    System.out.println("该图书没有借出!");
                    return;
                }
            }
        }
        System.out.println("没有该图书!");
    }
}
